﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

namespace Extjs_ReGSharp
{
	internal class TypePropertyWrapper<T>
	{
		#region Data Memebers

		private PropertyInfo m_Property;

		#endregion

		#region Private Methods

		private void GetPropertyByName(string field)
		{
			PropertyInfo[] properties = typeof(T).GetProperties();

			m_Property = properties.Where(p => string.Compare(p.Name, field, StringComparison.OrdinalIgnoreCase) == 0).FirstOrDefault();
		}

		#endregion

		#region Constructor

		public TypePropertyWrapper(string field)
		{
			GetPropertyByName(field);

			IsMemberValid = m_Property != null;
		}

		#endregion

		#region Properties

		internal PropertyInfo Property
		{
			get
			{
				PropertyInfo result = IsMemberValid ? m_Property : null;

				return result;
			}
		}

		internal bool IsMemberValid { get; private set; }

		internal Type FieldType
		{
			get
			{
				Type result = IsMemberValid ? m_Property.PropertyType : null;

				return result;
			}
		}

		#endregion
	}
}
